﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mathematics
{
    public abstract class MathExpression 
    {
        internal MathExpression()
        {

        }

        public abstract bool CanEvaluate();
        public abstract double? Evaluate();

        //public abstract IEnumerable<Variable> GetVariables();
        //public abstract IEnumerable<Constant> GetConstants();

        public MathExpression Simplify()
        {
            var currentExpression = this;
            bool didReduce;
            do
            {
                currentExpression = currentExpression.Reduce(out didReduce);
            } while (didReduce);
            return currentExpression;
        }

        protected internal abstract MathExpression Reduce(out bool didReduce);
    }
}
